package tokenmem

import (
	"github.com/spf13/viper"
	"gitee.com/zxs-micro/zxs-micro-auth/grpc/authserver/model"
)

type TokenMemImpl interface {
	MemType() string
	GetToken(string) (*model.TokenModel, error)
	AddToken(string, *model.TokenModel) error
	DeleteToken(string) error
}

var l map[string]TokenMemImpl

func init() {
	l = make(map[string]TokenMemImpl)
}

func GetTokenMemByType(types string) TokenMemImpl {
	impl, ok := l[types]
	if ok {
		return impl
	}
	switch types {
	case "redis":
		node := viper.GetString("redis.node")
		pwd := viper.GetString("redis.pwd")
		NewRedisTokenMem(node, pwd)
		l[types] = r
		return r
	case "rediscluster":
		//todo redis集群有待完成
		return nil
	case "local":
		NewLocalMem()
		l[types] = locals
		return locals
	//case "etcd":
	//	etcd := NewEtcdTokenMem()
	//	l[types] = etcd
	//	return etcd
	default:
		return nil
	}
}
